﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace E.Tool
{
    public class AutoLookAt : AutoComponent
    {
        [SerializeField] [Tooltip("观察类型")] private LookAtType type = LookAtType.Cursor;
        [SerializeField] [Tooltip("旋转对象")] private Transform self;
        [SerializeField] [Tooltip("观察目标")] private GameObject target;

        private Vector3 mpos;
        private Vector3 lookPos;

        public void Update()
        {
            Do();
        }

        public override void Do()
        {
            if (!self) self = transform;

            switch (type)
            {
                case LookAtType.Cursor:
                    mpos = Input.mousePosition;
                    mpos = Camera.main.ScreenToWorldPoint(mpos);
                    lookPos = new Vector3(mpos.x, mpos.y, 0);
                    self.LookAt(lookPos);
                    self.Rotate(new Vector3(0, 1, 0), 90);
                    self.Rotate(new Vector3(0, 0, -1), -90);
                    break;
                case LookAtType.Gameobject:
                    break;
                default:
                    break;
            }
        }

        public enum LookAtType
        {
            Cursor,
            Gameobject
        }
    }
}